package com.atguigu.demo;

import java.util.concurrent.CountDownLatch;

/**
 * @Author 孔德成
 * @Slogan 致敬大师，致敬未来的你
 * @date 2021/8/9
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t----结束自习，离开教室");
                // 每有一个同学走后，计数器--
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        // 阻塞主线程，计数器为0时，放行
        countDownLatch.await();

        System.out.println(Thread.currentThread().getName() + "----班长锁门，离开教室");
    }
}
